<?php
/*********************/
/*                   */
/*  Version : 5.1.0  */
/*  Author  : RM     */
/*  Comment : 071223 */
/*                   */
/*********************/

define( "JIEQI_MODULE_NAME", "system" );
require_once( "../global.php" );
include_once( JIEQI_ROOT_PATH."/class/power.php" );
$power_handler =& jieqipowerhandler::getinstance( "JieqiPowerHandler" );
$power_handler->getsavedvars( "system" );
jieqi_checkpower( $jieqiPower['system']['adminmessage'], $jieqiUsersStatus, $jieqiUsersGroup, false, true );
jieqi_loadlang( "report", JIEQI_MODULE_NAME );
jieqi_getconfigs( "system", "configs" );
jieqi_getconfigs( JIEQI_MODULE_NAME, "rsort", "jieqiRsort" );
if ( empty( $_REQUEST['page'] ) || !is_numeric( $_REQUEST['page'] ) )
{
		$GLOBALS['_REQUEST']['page'] = 1;
}
include_once( JIEQI_ROOT_PATH."/class/report.php" );
$report_handler = jieqireporthandler::getinstance( "JieqiReportHandler" );
if ( isset( $_REQUEST['checkaction'] ) && $_REQUEST['checkaction'] == 1 && is_array( $_REQUEST['checkid'] ) && 0 < count( $_REQUEST['checkid'] ) )
{
		$where = "";
		foreach ( $GLOBALS['_REQUEST']['checkid'] as $v )
		{
				if ( is_numeric( $v ) )
				{
						$v = intval( $v );
						if ( !empty( $where ) )
						{
								$where .= ", ";
						}
						$where .= $v;
				}
		}
		if ( !empty( $where ) )
		{
				$sql = "DELETE FROM ".jieqi_dbprefix( "system_report" )." WHERE reportid IN (".$where.")";
				$report_handler->db->query( $sql );
		}
		$GLOBALS['_REQUEST']['checkaction'] = 0;
}
if ( isset( $_GET['checkaction'] ) )
{
		unset( $_GET['checkaction'] );
}
if ( isset( $_POST['checkaction'] ) )
{
		unset( $_POST['checkaction'] );
}
include_once( JIEQI_ROOT_PATH."/admin/header.php" );
$jieqiTpl->assign( "checkall", "<input type=\"checkbox\" id=\"checkall\" name=\"checkall\" value=\"checkall\" onclick=\"javascript: for (var i=0;i<this.form.elements.length;i++){ if (this.form.elements[i].name != 'checkkall') this.form.elements[i].checked = form.checkall.checked; }\">" );
$reportrows = array( );
$criteria = new criteriacompo( );
if ( !empty( $_REQUEST['keyword'] ) || !empty( $_REQUEST['keytype'] ) )
{
		switch ( $_REQUEST['keytype'] )
		{
		case "reportname" :
				$criteria->add( new criteria( "reportname", $_REQUEST['keyword'] ) );
				break;
		case "authname" :
				$criteria->add( new criteria( "authname", $_REQUEST['keyword'] ) );
				break;
		case "reporttitle" :
				$criteria->add( new criteria( "reporttitle", "%".$_REQUEST['keyword']."%", "LIKE" ) );
		}
		$GLOBALS['_GET']['keyword'] = $_REQUEST['keyword'];
		$GLOBALS['_GET']['keytype'] = $_REQUEST['keytype'];
}
$criteria->setsort( "reportid" );
$criteria->setorder( "DESC" );
$criteria->setlimit( $jieqiConfigs['system']['messagepnum'] );
$criteria->setstart( ( $_REQUEST['page'] - 1 ) * $jieqiConfigs['system']['messagepnum'] );
$report_handler->queryobjects( $criteria );
$k = 0;
while ( $v = $report_handler->getobject( ) )
{
		$reportrows[$k]['checkbox'] = "<input type=\"checkbox\" id=\"checkid[]\" name=\"checkid[]\" value=\"".$v->getvar( "reportid" )."\">";
		$reportrows[$k]['reportid'] = $v->getvar( "reportid" );
		$reportrows[$k]['reporttime'] = $v->getvar( "reporttime" );
		$reportrows[$k]['reportuid'] = $v->getvar( "reportuid" );
		$reportrows[$k]['reportname'] = $v->getvar( "reportname" );
		$reportrows[$k]['authtime'] = $v->getvar( "authtime" );
		$reportrows[$k]['authuid'] = $v->getvar( "authuid" );
		$reportrows[$k]['authname'] = $v->getvar( "authname" );
		$reportrows[$k]['reporttitle'] = $v->getvar( "reporttitle" );
		$reportrows[$k]['reporttext'] = $v->getvar( "reporttext" );
		$reportrows[$k]['reportsize'] = $v->getvar( "reportsize" );
		$reportrows[$k]['reportfield'] = $v->getvar( "reportfield" );
		$reportrows[$k]['authnote'] = $v->getvar( "authnote" );
		$reportrows[$k]['reportsort'] = intval( $v->getvar( "reportsort" ) );
		$reportrows[$k]['reporttype'] = intval( $v->getvar( "reporttype" ) );
		$reportrows[$k]['authflag'] = $v->getvar( "authflag" );
		$reportrows[$k]['sortname'] = $jieqiRsort[$reportrows[$k]['reportsort']]['caption'];
		if ( isset( $jieqiRsort[$reportrows[$k]['reportsort']]['types'][$reportrows[$k]['reporttype']] ) )
		{
				$reportrows[$k]['typename'] = $jieqiRsort[$reportrows[$k]['reportsort']]['types'][$reportrows[$k]['reporttype']];
		}
		else
		{
				$reportrows[$k]['typename'] = $jieqiLang['system']['report_type_other'];
		}
		++$k;
}
$jieqiTpl->assign_by_ref( "reportrows", $reportrows );
$jieqiTpl->assign_by_ref( "rsortrows", $jieqiRsort );
include_once( JIEQI_ROOT_PATH."/lib/html/page.php" );
$jumppage = new jieqipage( $report_handler->getcount( $criteria ), $jieqiConfigs['system']['messagepnum'], $_REQUEST['page'] );
$jieqiTpl->assign( "url_jumppage", $jumppage->whole_bar( ) );
$jieqiTpl->setcaching( 0 );
$jieqiTset['jieqi_contents_template'] = JIEQI_ROOT_PATH."/templates/admin/reportlist.html";
include_once( JIEQI_ROOT_PATH."/admin/footer.php" );
?>
